# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgbase=readline
pkgname=('libreadline' 'libreadline-devel')
_basever=7.0
_patchlevel=005 #prepare for some patches
pkgver=${_basever}.${_patchlevel}
pkgrel=1
pkgdesc="GNU readline library"
arch=('i686' 'x86_64')
url="https://tiswww.case.edu/php/chet/readline/rltop.html"
license=('GPL')
makedepends=('ncurses-devel')
#backup=('etc/inputrc')
options=('!emptydirs')
source=(https://ftp.gnu.org/gnu/readline/readline-$_basever.tar.gz{,.sig}
        readline-7.0.3-3.clipboard.patch
        readline-7.0.3-3.src.patch
        readline-6.3-msys2.patch
        readline-6.3-paste-utf8.patch)
if [ $_patchlevel -gt 00 ]; then
    for (( p=1; p<=$((10#${_patchlevel})); p++ )); do
        source=(${source[@]} https://ftp.gnu.org/gnu/readline/readline-${_basever}-patches/readline${_basever//./}-$(printf "%03d" $p){,.sig})
    done
fi
sha256sums=('750d437185286f40a369e1e4f4764eda932b9459b5ec9a731628393dd3d32334'
            'SKIP'
            '82289eeb21941e4b273839de68058d9f7901379615f9a481102eb874f34a7235'
            'ebb548dfd63305dff579c223857944fbf756360498ae748df4357da243f0687d'
            '4f2f97334d2e7fe362c9ef4e1fd06018d34115a8370c0323d0da67ca2b3d0761'
            '2142f1417536e2670829d3cf6f4f4f2560687a92955ccf11a121bde5dbbccbc9'
            '9ac1b3ac2ec7b1bf0709af047f2d7d2a34ccde353684e57c6b47ebca77d7a376'
            'SKIP'
            '8747c92c35d5db32eae99af66f17b384abaca961653e185677f9c9a571ed2d58'
            'SKIP'
            '9e43aa93378c7e9f7001d8174b1beb948deefa6799b6f581673f465b7d9d4780'
            'SKIP'
            'f925683429f20973c552bff6702c74c58c2a38ff6e5cf305a8e847119c5a6b64'
            'SKIP'
            'ca159c83706541c6bbe39129a33d63bbd76ac594303f67e4d35678711c51b753'
            'SKIP')
validpgpkeys=('7C0135FB088AAF6C66C650B9BB5869F064EA74AB') # Chet Ramey

prepare() {
  cd ${srcdir}/${pkgbase}-${_basever}
  for (( p=1; p<=$((10#${_patchlevel})); p++ )); do
    msg "applying patch readline${_basever//./}-$(printf "%03d" $p)"
    patch -p0 -i $srcdir/readline${_basever//./}-$(printf "%03d" $p)
  done
  patch -p2 -i ${srcdir}/readline-7.0.3-3.src.patch
  patch -p1 -i ${srcdir}/readline-6.3-msys2.patch
  patch -p1 -i ${srcdir}/readline-6.3-paste-utf8.patch
  patch -p1 -i ${srcdir}/readline-7.0.3-3.clipboard.patch
}

build() {
  cd ${srcdir}/${pkgbase}-${_basever}

  # Remove RPATH from shared objects (FS#14366)
  sed -i 's|-Wl,-rpath,$(libdir) ||g' support/shobj-conf

  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --host=${CHOST} \
    --with-curses \
    bash_cv_termcap_lib=libncurses
  make VERBOSE=1

  make DESTDIR=${srcdir}/dest install
}

package_libreadline() {
  depends=('ncurses')
  groups=('libraries')
  install=readline.install

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_libreadline-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("libreadline=${pkgver}" 'ncurses-devel')
  pkgdesc="readline headers and libraries"

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
